import {
	ref
} from 'vue'
const useSmsCode = (value) => {
	const defaultTime = value;
	const btnCodeText = ref('获取验证码');
	const status = ref(false);
	const time = ref(defaultTime);

	const timer = ref(null);

	const changeStatus = () => {
		status.value = true;

		timer.value = setInterval(() => {
			time.value -= 1;
			btnCodeText.value = `${time.value}s`;
			if (time.value === 0) {
				status.value = false;
				btnCodeText.value = '获取验证码';
				time.value = defaultTime;
				clearInterval(timer.value);
			}
		}, 1000)
	}
	return {
		btnCodeText,
		status,
		changeStatus
	};
}

export default useSmsCode;